package com.example.publishDemo.Mapper;


import com.example.publishDemo.Model.User;
import com.example.publishDemo.Model.UserRelation;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("select * from user")
    List<User> userlist();

//    --------  没用
    @Insert("insert into user(username, password, gender) values(#{username}, #{password}, #{gender})")
    int addUser(String username, String password, String gender);

    @Select("select * from user where username = #{username} and password = #{password}")
    User findOne(String username, String password);
//    ---------

    @Select("select * from user where username=#{username} and u_id <> #{u_id}")
    List<User> checkNameExcludingMe(String username,int u_id);

    @Select("select * from user where username=#{username}")
    List<User> checkName(String username);

    @Delete("delete from user where u_id=#{u_id}")
    int delUser(int u_id);

    @Insert("insert into user(username, password, birthday) values(#{username}, #{password}, #{birthday})")
    int regist(User user);

    @Select("select * from user where username = #{username} and password = #{password}")
    User login(User user);

    @Update("update user set status = #{userStatus} where u_id=#{u_id}")
    int changUserStatus(int u_id, String userStatus);

    @Update("update user set username = #{username}, password = #{password} where u_id=#{u_id}")
    int changeUserInfo(String username, String password,int u_id);

    @Update("update user set picture = #{picture} where u_id=#{u_id}")
    int changeUserGravatar(String picture, int u_id);

    @Select("select * from user where u_id=#{u_id}")
    User findById(int u_id);


//    UserRelation的部分
    @Insert("insert into user_relation(focus_id,focused_id) values(#{focus_id}, #{focused_id})")
    int buildRelationship(int focus_id, int focused_id);

    @Select("select * from user_relation where focus_id = #{focus_id} and focused_id = #{focused_id}")
    List<UserRelation> isRelation(int focus_id, int focused_id);

    @Select("select focused_id from user_relation where focus_id = #{u_id}")
    List<Integer> userFocused(int u_id);

    @Select("select * from user_relation where focused_id = #{u_id}")  //focused_id：被关注者的Id
    List<User> getUserFansForId(int u_id);

    @Select("select focused_id from user_relation where focus_id = #{u_id}")    //focus_id：被关注者的Id
    List<Integer> GetAllUsersOfFocusId(int u_id);

    @Delete("delete from user_relation where focus_id=#{focus_id} and focused_id=#{focused_id}")
    int UnFollow(int focus_id, int focused_id);
}
